<?php
//force redirect to secure page
if(REG_USE_SSL){
	if($_SERVER['SERVER_PORT'] != '443') 
	{ 
		header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); 
		exit(); 
	}
}
session_start();

// includes
include_once "regsettings.php";

include_once REG_CONNECT_FILE;
include_once REG_QUERY_FILE;

$mode = $_REQUEST['mode'];

if (empty($_REQUEST['user_id'])){
	$mode = 'Add';
}
	

// go into add mode if user does not exist, and show link to login
	if($mode == 'Add'){
		$mode = "Add";
		$loginlink = "<br/><a href='login.php?referrer=" . $_SERVER['PHP_SELF'] . "'>Already Registered? Login Here</a><br/>";

	}else{

		if(($_SESSION['grant_permission'] == 1) AND (!empty($_REQUEST['user_id']))){
			$user_id = $_REQUEST['user_id'];
			// exti if grant privileg is not there.
		}else if(!empty($_SESSION['user_id'])){
			$user_id = $_SESSION['user_id'];
		}
		$hide_user_id = "<input type='hidden' name='user_id' value='$user_id' />";
		$mode = "Save";
	
		$qry_list = "SELECT user_id, username, password, firstname, lastname, email FROM " . REG_USER_TABLE . " WHERE 1 AND user_id = $user_id  ";	
		$array_list = get_array_query($qry_list);

		$values = $array_list[0];
	}
	

	$link_vars = "?user_id=$user_id";
	//print_r($SESSION);
		
	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Registration</title>

</head>
<body>

			
<div id="topnote">

 </div> <!-- end tonote -->
 
<div id="maincontent" >
	<?php print $_REQUEST['message']; ?>
<h2>Account Information</h2>
<form name="regform" method="get" action="regs_proc.php" id="regform">
<div id="entry_username" class="entries">
<div class="heading">Username</div>
<div class="input"><input type="text" size="20" name="username" id="username" value="<?php print $values['username'] ?>" /></div>
</div>
<div id="entry_password" class="entries">
<div class="heading">Enter Password</div>
<div class="input"><input type="password" size="12" name="password" id="password" value="<?php print $values['password'] ?>" /></div>
</div>
<div id="entry_password" class="entries">
<div class="heading">Re-Enter Password</div>
<div class="input"><input type="password" size="12" name="check_password" id="check_password" value="<?php print $values['password'] ?>" /></div>
</div>
<div id="entry_firstname" class="entries">
<div class="heading">First Name</div>
<div class="input"><input type="text" size="40" name="firstname" id="firstname" value="<?php print $values['firstname'] ?>" /></div>
</div>
<div id="entry_lastname" class="entries">
<div class="heading">Last Name</div>
<div class="input"><input type="text" size="40" name="lastname" id="lastname" value="<?php print $values['lastname'] ?>" /></div>
</div>
<div id="entry_email" class="entries">
<div class="heading">E-Mail</div>
<div class="input"><input type="text" size="40" name="email" id="email" value="<?php print $values['email'] ?>" /></div>
</div>
<div class="controls">
<?php print $hide_user_id ?>
<input type="hidden" name="mode" value="<?php print $mode ?>" />
<input type="submit" value="<?php print $mode ?>" /></div>
</form>

</div> <!-- end maincontent -->


</body>
</html>